


  // 获取所有的幻灯片和指示点
  const slides = document.querySelectorAll('.slide');
  const indicators = document.querySelectorAll('.slider-indicators button');

  // 初始化当前幻灯片索引
  let currentSlide = 0;

  // 自动播放函数
  function autoPlay() {
    currentSlide++;
    if (currentSlide >= slides.length) {
      currentSlide = 0;
    }
    updateSlide();
  }

  // 设置自动播放间隔（每 3 秒切换一次）
  setInterval(autoPlay, 3000);

  // 点击下一张按钮
  document.getElementById('nextBtn').addEventListener('click', () => {
    currentSlide++;
    if (currentSlide >= slides.length) {
      currentSlide = 0;
    }
    updateSlide();
  });

  // 点击上一张按钮
  document.getElementById('prevBtn').addEventListener('click', () => {
    currentSlide--;
    if (currentSlide < 0) {
      currentSlide = slides.length - 1;
    }
    updateSlide();
  });

  // 点击指示点切换幻灯片
  indicators.forEach((indicator, index) => {
    indicator.addEventListener('click', () => {
      currentSlide = index;
      updateSlide();
    });
  });

  // 更新幻灯片显示
  function updateSlide() {
    slides.forEach(slide => slide.classList.remove('active'));
    indicators.forEach(indicator => indicator.classList.remove('active'));
    slides[currentSlide].classList.add('active');
    indicators[currentSlide].classList.add('active');
  }